﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging ;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AnyOffice.Components;
using AnyOffice.DAL;
using System.Reflection;
using log4net;


namespace AnyOffice.general.ipanel
{
    public partial class photo : Page
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
       
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string str = (Request.QueryString["user_id"] == null) ? "" : Request.QueryString["user_id"].ToString();
                if (str != string.Empty)
                {
                    string cmdText = "select Photo from Users where UserId='" + str + "'";
                    SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                    connection.Open();
                    object obj2 = new SqlCommand(cmdText, connection).ExecuteScalar();
                    if ((obj2 != null) && (obj2 != DBNull.Value))
                    {
                        byte[] buffer = (byte[])obj2;
                        if (connection.State == ConnectionState.Open)
                        {
                            connection.Close();
                        }
                        MemoryStream stream = new MemoryStream();
                        stream.Write(buffer, 0, buffer.Length);
                        Bitmap bitmap = new Bitmap(stream);
                        Response.ContentType = "image/jpeg";
                        bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
                    }
                }
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("", exception);
                }
            }
        } 

    }
}
